package com.imooc.controller;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.util.StringUtils;
import com.imooc.result.CodeMsg;
import com.imooc.result.Result;
import com.imooc.service.MiaoshaUserService;
import com.imooc.utils.ValidateUtil;
import com.imooc.vo.LoginVo;


@Controller
@RequestMapping("/login")
public class LoginController {
	
	private Logger log = LoggerFactory.getLogger(LoginController.class);
	
	@Autowired
	private MiaoshaUserService userService;
	
	@RequestMapping("/to_login")
	public String toLogin(){
		return "login";
	}
	
	@RequestMapping("/do_login")
	@ResponseBody
	public Result<Boolean> doLogin(HttpServletResponse response, 
			@Valid LoginVo vo){
		
		
		
		//参数校验
//		String password = vo.getPassword();
//		String mobile = vo.getMobile();
//		if(StringUtils.isEmpty(password)){
//			return Result.error(CodeMsg.PASSWORD_EMPTY);
//		}
//		if(StringUtils.isEmpty(mobile)){
//			return Result.error(CodeMsg.MOBILE_EMPTY);
//		}
//		if(!ValidateUtil.isMobile(mobile)){
//			return Result.error(CodeMsg.MOBILE_ERROR);
//		}
		System.out.println("==========login");
		//登录
		CodeMsg cm = userService.login(response, vo);
		return Result.success(true);
		
	}
}
